package step1_homework4_04;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class Client {


        public static void main(String[] args) {
            Socket s = null;
            ObjectInputStream in = null;
            ObjectOutputStream out = null;
            try {
                s = new Socket("127.0.0.1",4444);
                User user=new User("admin","12345");
                UserMessage um=new UserMessage();
                um.setUser(user);
                // 创建对象输出流
                out = new ObjectOutputStream(s.getOutputStream());
                // 发出对象
                out.writeObject(um);
                // 创建对象输入流
                in = new ObjectInputStream(s.getInputStream());
                // 获取服务端返回的UserMessage对象
                try {
                    um = (UserMessage)in.readObject();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
                // 打印结果
                if ("success".equals(um.getTYPE())) {
                    System.out.println("登陆成功");
                }else{
                    System.out.println("登陆失败");
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if(null != s){
                    try {
                        s.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
}

